package com.woniuxy.qiantai.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MercantileOrderMQConfig {
    //商家死信交换机
    @Bean
    public DirectExchange MercantileDeadExchange(){
        return new DirectExchange("MercantileDeadExchange");
    }
    //商家死信队列
    @Bean
    public Queue MercantileDeadQueue(){
        return new Queue("MercantileDeadQueue");
    }
    //用户死信交换机和队列绑定
    @Bean
    public Binding MercantileDeadBinding(){
        return BindingBuilder.bind(MercantileDeadQueue())
                .to(MercantileDeadExchange())
                .with("MercantileDeadRouting");
    }

    //商家普通交换机
    @Bean
    public DirectExchange MercantileNormalExchange(){
        return new DirectExchange("MercantileNormalExchange");
    }
    //用户普通交换机和普通队列绑定
    @Bean
    public Binding MercantileNormalBinding(){
        return BindingBuilder.bind(MercantileNormalQueue())
                .to(MercantileNormalExchange())
                .with("MercantileNormalRouting");
    }

    //商家普通队列和死信交换机绑定
    @Bean
    public Queue MercantileNormalQueue(){
        return QueueBuilder.durable("MercantileNormalQueue")
                .deadLetterExchange("MercantileDeadExchange")
                .deadLetterRoutingKey("MercantileDeadRouting")
                .ttl(2*60*1000)
                .build();
    }
}
